home *** CD-ROM | disk | FTP | other *** search
/ APDL Other Worlds / APDL Other Worlds Collection.iso / SF3000 / Extras / CBlibrary / s / timer
Encoding:
Text File  |  2003-10-16  |  2.7 KB  |  99 lines

  1. ;
  2. ; CBLibrary
  3. ; Copyright (C) 2003  Chris Bazley
  4. ;
  5. ; This library is free software; you can redistribute it and/or
  6. ; modify it under the terms of the GNU Lesser General Public
  7. ; License as published by the Free Software Foundation; either
  8. ; version 2.1 of the License, or (at your option) any later version.
  9. ;
  10. ; This library is distributed in the hope that it will be useful,
  11. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ; Lesser General Public License for more details.
  14. ;
  15. ; You should have received a copy of the GNU Lesser General Public
  16. ; License along with this library; if not, write to the Free Software
  17. ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. ;
  19.  
  20. ; Support code for psuedo pre-emptive multitasking
  21. ; 11.09.03 CJB Added BOOL_8_BIT variable to control width of type 'bool'.
  22.  
  23.   EXPORT timer_register
  24.   EXPORT timer_deregister
  25.  
  26.   AREA |C$$code|, CODE, READONLY
  27.  
  28. Auto_Error_SWI_bit_number * 17
  29. Auto_Error_SWI_bit * 1 :SHL: Auto_Error_SWI_bit_number
  30.  
  31. XOS_CallAfter         * &3B + Auto_Error_SWI_bit
  32. XOS_RemoveTickerEvent * &3D + Auto_Error_SWI_bit
  33.  
  34.   GBLL BOOL_8_BIT
  35. BOOL_8_BIT SETL {TRUE}
  36. ; This controls whether the type 'bool' is 8 or 32 bits wide.
  37. ; The stdbool header supplied with recent versions of Castle's C compiler (5.50 and later?) defines 'bool' as the built-in 8 bit type '_Bool'.
  38. ; However the stdbool header supplied with earlier compiler releases instead defined 'bool' as 'int' (32 bits wide).
  39.  
  40. timer_set_flag
  41.   ; Called in SVC mode with interrupts disabled
  42.   ; Must preserve all registers and return using MOV PC,R14
  43.   ; R12 = pointer to timeup flag
  44.  
  45.   STR R14,[R13,#-4]! ; push return address
  46.  
  47.   MOV R14,#1
  48.   [ BOOL_8_BIT
  49.   STRB R14,[R12] ; set flag byte
  50.   |
  51.   STR R14,[R12] ; set flag word
  52.   ]
  53.  
  54.   LDR PC,[R13],#4 ; pull return address
  55.  
  56.  
  57. ; _kernel_oserror *timer_register(volatile bool *timeup_flag, unsigned int wait_time)
  58. timer_register
  59.   ; a1 = pointer to bool
  60.   ; a2 = delay in cs
  61.   MOV ip,lr
  62.  
  63.   MOV lr,#0
  64.   [ BOOL_8_BIT
  65.   STRB lr,[a1] ; clear flag byte
  66.   |
  67.   STR lr,[a1] ; clear flag word
  68.   ]
  69.  
  70.   MOV a3,a1 ; R12 value for routine is pointer to flag
  71.   MOV a1,a2 ; delay in cs
  72.   ADR a2,timer_set_flag ; pointer to routine
  73.   SWI XOS_CallAfter
  74.     MOVVC a1,#0 ; if no error then return NULL
  75.  
  76.   [ {CONFIG} = 26
  77.   MOVS pc,ip ; APCS-R
  78.   |
  79.   MOV pc,ip ; APCS-32
  80.   ]
  81.  
  82.  
  83. ; _kernel_oserror *timer_deregister(volatile bool *timeup_flag)
  84. timer_deregister
  85.   ; a1 = pointer to bool 
  86.   MOV ip,lr
  87.   MOV a2,a1 ; R12 value for routine is pointer to flag
  88.   ADR a1,timer_set_flag ; pointer to routine
  89.   SWI XOS_RemoveTickerEvent
  90.     MOVVC a1,#0 ; if no error then return NULL
  91.  
  92.   [ {CONFIG} = 26
  93.   MOVS pc,ip ; APCS-R
  94.   |
  95.   MOV pc,ip ; APCS-32
  96.   ]
  97.  
  98.   END
  99.